#pragma once
#include <iostream>
#include "open_hash.hpp"
#include "hash_func.hpp"

namespace test
{

template<class K, class Hash = hash<K>>
class unordered_set
{
private:
    struct KeyOfVal
    {
        const K& operator()(const K& key) const
        {
            return key;
        }
    };

public:
    typedef hash_table<K, K, Hash, KeyOfVal> rep_type;
    typedef typename rep_type::const_iterator iterator;
    typedef typename rep_type::const_iterator const_iterator;

public:
    std::pair<iterator, bool> insert(const K& key)
    {
        return _ht.insert(key);
    }

    size_t erase(const K& key)
    {
        return _ht.erase(key);
    }

    iterator find(const K& key)
    {
        return _ht.find(key);
    }

    iterator begin()
    {
        return _ht.begin();
    }

    iterator end()
    {
        return _ht.end();
    }

    const_iterator begin() const
    {
        return _ht.begin();
    }

    const_iterator end() const
    {
        return _ht.end();
    }

private:
    rep_type _ht;
};

void test_unordered_set()
{
    int a[] = {3, 33, 2, 13, 5, 12, 1022};
    unordered_set<int> s;
    //s.insert(1);
    //s.insert(2);
    //s.insert(3);
    //s.insert(4);
    //s.insert(5);
    //s.insert(6);

    for (auto e : a)
    {
        s.insert(e);
    }

    unordered_set<int>::iterator it = s.begin();
    while (it != s.end())
    {
        // *it = 1; // ERR
        std::cout << *it << " ";
        ++it;
    }
    std::cout << std::endl;
}

}
